package com.hctforgreen.greenservice.threeLevelList;

import com.hctforgreen.greenservice.model.BookListEntity;
import com.hctforgreen.greenservice.model.SerieListEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * http://blog.csdn.net/lmj623565791/article/details/40212367
 * @author zhy
 *
 */
public class Node
{

	private String id;
	/**
	 * 根节点pId为0
	 */
	private String pId = "0";
	/**
	 * 书名
	 */
	private String bookName;

	/**
	 * 书籍大小
	 */
	private String bookSize;
	/**
	 * 子系列数量
	 */
	private int seriesCounts = -1;
	/**
	 * 书籍实体
	 */
	private BookListEntity.BookEntity bookEntity;
	/**
	 * 子系列实体
	 */
	private SerieListEntity.ChildSerieEntity childSerieEntity;
	/**
	 * 系列实体
	 */
	private SerieListEntity.SerieEntity seriesEntity;

	/**
	 * 当前的级别
	 */
	private int level;

	/**
	 * 是否展开
	 */
	private boolean isExpand = false;

	private int icon;

	/**
	 * 下一级的子Node
	 */
	private List<Node> children = new ArrayList<Node>();

	/**
	 * 父Node
	 */
	private Node parent;

	public Node()
	{
	}

	public Node(String id, String pId, String name,String bookSize,int seriesCounts
	/*,BookListEntity.BookEntity bookEntity,SerieListEntity.ChildSerieEntity childSerieEntity,
				SerieListEntity.SerieEntity seriesEntity*/)
	{
		super();
		this.id = id;
		this.pId = pId;
		this.bookName = name;
		this.bookSize = bookSize;
		this.seriesCounts = seriesCounts;
	}

	public int getIcon()
	{
		return icon;
	}

	public void setIcon(int icon)
	{
		this.icon = icon;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getpId()
	{
		return pId;
	}

	public void setpId(String pId)
	{
		this.pId = pId;
	}

	public String getBookName() {
		return bookName;
	}

	public void setBookName(String bookName) {
		this.bookName = bookName;
	}

	public void setLevel(int level)
	{
		this.level = level;
	}

	public boolean isExpand()
	{
		return isExpand;
	}

	public List<Node> getChildren()
	{
		return children;
	}

	public void setChildren(List<Node> children)
	{
		this.children = children;
	}

	public Node getParent()
	{
		return parent;
	}

	public void setParent(Node parent)
	{
		this.parent = parent;
	}

	public String getBookSize() {
		return bookSize;
	}

	public void setBookSize(String bookSize) {
		this.bookSize = bookSize;
	}

	public int getSeriesCounts() {
		return seriesCounts;
	}

	public void setSeriesCounts(int seriesCounts) {
		this.seriesCounts = seriesCounts;
	}

	public BookListEntity.BookEntity getBookEntity() {
		return bookEntity;
	}

	public void setBookEntity(BookListEntity.BookEntity entity) {
		this.bookEntity = entity;
	}

	public SerieListEntity.ChildSerieEntity getChildSerieEntity() {
		return childSerieEntity;
	}

	public void setChildSerieEntity(SerieListEntity.ChildSerieEntity childSerieEntity) {
		this.childSerieEntity = childSerieEntity;
	}

	public SerieListEntity.SerieEntity getSeriesEntity() {
		return seriesEntity;
	}

	public void setSeriesEntity(SerieListEntity.SerieEntity seriesEntity) {
		this.seriesEntity = seriesEntity;
	}

	/**
	 * 是否为跟节点
	 * 
	 * @return
	 */
	public boolean isRoot()
	{
		return parent == null;
	}

	/**
	 * 判断父节点是否展开
	 * 
	 * @return
	 */
	public boolean isParentExpand()
	{
		if (parent == null)
			return false;
		return parent.isExpand();
	}

	/**
	 * 是否是叶子界点
	 * 
	 * @return
	 */
	public boolean isLeaf()
	{
		return children.size() == 0;
	}

	/**
	 * 获取level
	 * 得到当前节点的层级，如果当前的节点没有父节点，则该节点是根节点、
	 * 否则当前节点的层级为当前父节点的层级加1
	 */
	public int getLevel()
	{
		return parent == null ? 0 : parent.getLevel() + 1;
	}

	/**
	 * 设置当前节点是否展开，如果是false，那么递归关闭当前节点的所有子节点
	 * 
	 * @param isExpand
	 */
	public void setExpand(boolean isExpand)
	{
		this.isExpand = isExpand;
		if (!isExpand)
		{

			for (Node node : children)
			{
				node.setExpand(isExpand);
			}
		}
	}
}
